﻿#include <iostream>
using namespace std;
class Base
{
public:
	Base(){}
	virtual ~Base(){}
	virtual void print() { cout << "Base::print()" << endl; }
};
class A :public Base
{
public:
	A() {}
	virtual ~A() {}
	virtual void print() { cout << "A::print()" << endl; }
};
class B :public Base
{
public:
	B() {}
	virtual ~B() {}
	virtual void print() { cout << "B::print()" << endl; }
};
Base* Factory(char t)
{
	switch (t) {
	case 'A':
	case 'a':
		return new A;
		break;
	case 'B':
	case 'b':
		return new B;
		break;
	default:
		break;
	}
}
int main()
{
	Base* a = Factory('A');
	Base* b = Factory('B');
	a->print();
	b->print();
	delete a;
	a = nullptr;
	delete b;
	b = nullptr;
	return 0;
}
